<?php
    function getLink(){
    $dbServer = "localhost";
    $dbUser = "root";
    $dbPass = "";
        $link = mysql_connect ( $dbServer , $dbUser , $dbPass );
        mysql_select_db("Kioskos" , $link);
        return $link;
    }
    function getTable($query , $linkToUse = null){
        
        $link = is_null($linkToUse)?getLink():$linkToUse;
        
        $result = mysql_query($query , $link);
        
        //echo $result;
        $retVal = array();
        while($row = mysql_fetch_assoc($result)){
            $retVal[] = $row;
        }
        if( is_null($linkToUse))
        mysql_close($link);
        return $retVal;
    }
    function getScalar($query ,$link = null){
        $t = getTable($query , $link);
        var_dump($t);
        foreach($t as $rows){
            foreach($rows as $retVal){
                return $retVal;
             }
        }
        return null;
    }
    function execute( $query )
    {
        try{
            $link = getLink();
            mysql_query($query);
            $lastId = getScalar("SELECT LAST_INSERT_ID();",$link);
            mysql_close($link);
            return is_numeric($lastId)?$lastId:"SUCCESS!! " ;
        }catch(Exception $ex){
            return var_export($ex);
        }
    }
?>